public class Test {
}



 class ListNode {
     int val;
      ListNode next;
   ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }

class Solution {
    public ListNode reverseList(ListNode head) {

        if(head==null){
            return head;
        }

        if(head.next==null){
            return head;
        }

        ListNode cur=head;

        ListNode next=head.next;
        ListNode node=next.next;
        head.next=null;
        while(next!=null){
            next.next=cur;
            cur=next;
            next=node;
            if(node!=null){
                node=node.next;
            }


        }


        return cur;

    }
}